package com.example.testapplication;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

/**
 * @author wwq on 2019/7/25  10:09.
 */
public class RecyclerViewFollowAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    public  class ViewHolder extends RecyclerView.ViewHolder{
        TextView title;
        ViewHolder(View v) {
            super(v);
            title = v.findViewById(R.id.articleTitle);
        }
    }

    private List<Question> titleList;

    RecyclerViewFollowAdapter(List<Question> list){
        this.titleList = list;
    }


    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view;
        switch (i){
            case 0:
                view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.follow_type_1,viewGroup,false);
                return new ViewHolder(view);
            case 1:
                view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.follow_type_2,viewGroup,false);
                return new ViewHolder(view);
            case 2:
                view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.follow_type_3,viewGroup,false);
                return new ViewHolder(view);
            case 3:
                view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.follow_type_4,viewGroup,false);
                return new ViewHolder(view);
            default:
                return null;
        }
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
        Question title = titleList.get(i);
        ((ViewHolder)viewHolder).title.setText(title.getTitle());
    }

    @Override
    public int getItemCount() {
        return titleList.size();
    }

    @Override
    public int getItemViewType(int position) {
        switch (position % 4){
            case 0:
                return 0;
            case 1:
                return 1;
            case 2:
                return 2;
            case 3:
                return 3;
            default:
                break;
        }
        return super.getItemViewType(position);
    }


}
